<div class="easyui-panel" data-options="fit:true,border:false" style="padding:10px;">
    <div class="easyui-layout" fit='true' style="width:700px;height:350px;">
        <div data-options="region:'north'" style="height:120px; padding-top:10px;" title="检索选项">
            <form id="worklog_manage_ff" method="post">
                <table cellpadding="5">
                    <tr>
                        <td align="right">人员:</td>
                        <td><input id="worklog_manage_search_select_user" class="textbox" data-options="multiple:true,icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).textbox('clear');}}]" style="width:200px; height:24px; cursor:pointer;" onclick="selectuser_fun('选择用户','worklog_manage_search')"></td>
                        <td align="right">职务:</td>
                        <td><input class="easyui-combobox" id="role_id_log" name="role_id_log" editable="false" data-options="url:'<?php echo base_url('systemmanage/role_data_select');?>',panelHeight:'300',valueField:'id',textField:'text',multiple:true,multiline:true,icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('clear');}}]" style="width:200px; height:24px;"></td>
                        <td align="right"></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td align="right">开始时间:</td>
                        <td><input id="worklog_manage_ids" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#worklog_manage_id',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).datebox('clear');}}]" style="width:200px; height:24px;"></td>
                        <td align="right">结束时间:</td>
                        <td><input id="worklog_manage_ide" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#worklog_manage_id',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).datebox('clear');}}]" style="width:200px; height:24px;"></td>
                        <td></td>
                        <td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="worklog_manage_search_submit('worklog_manage')">搜索</a>
                        <input id="worklog_manage_search_select_id" type="hidden">
                        <div id="worklog_manage_id" class="easyui-calendar"></div></td>
                    </tr>             
                </table>
                
            </form>
        </div>
        <div data-options="region:'center'" title="检索结果">
            <table id="worklog_manage_list"></table>
        </div>
    </div>
</div>
<div id="worklog_manage_ft" style="padding:2px 5px;">
    <a class="easyui-linkbutton" onclick="worklog_table('worklog_manage')" iconCls="icon-add" plain="true">结果导出为Excel</a>
</div>
<!--带限制的选择用户容器-->
<div id="selectuser_dd_stint" class="easyui-dialog" style="width:450px;height:400px;padding:5px;" data-options="iconCls:'icon-user',resizable:true,modal:true,closed: true">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'east',split:true" style="width:210px">
            <div id="selectuser_list_stint" class="easyui-datagrid" title="单击部门名称或勾选" border="false"></div>
        </div>
        <div data-options="region:'center'" style="padding:10px;">
            <ul id="selectuser_tree_stint" class="easyui-tree" data-options="
                url:'<?php echo base_url('worklog/getdeptdata_stint')?>',
                method:'get',
                animate:true,
                checkbox:true,
                fit:true
            "></ul>
        </div>
        <div data-options="region:'south'" style="text-align:right; height:40px; padding-top:5px; border-width:1px 0 0 0; overflow:hidden">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#selectuser_dd_stint').dialog('close')" style="width:80px">确定</a>
            <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:clearuser_stint()" style="width:80px">清空</a>
        </div>
    </div>
</div>
<script>
$('#worklog_manage_ids').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date>d1){
			$('#worklog_manage_ids').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','开始日期不能大于当前日期','warning');
		}
	}
});
$('#worklog_manage_ide').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date>d1){
			$('#worklog_manage_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不能大于当前日期','warning');
		}
		var eids = $("#worklog_manage_ids").datebox('getValue');
		var newDt=new Date(eids.replace("-","/")); 
		if(eids != '' && date<newDt){
			$('#worklog_manage_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不能小于开始日期','warning');
		}
	}
});


$('#worklog_manage_list').datagrid({
	url:'<?php echo base_url('worklog/log_data_manage');?>',
	singleSelect:true,
	rownumbers:true,
	pagination:true,
	pageSize:50,
	pageList:[30,50,100],
	fit:true,
	fitColumns:true,
	border:false,
	queryParams:{},
	footer:'#worklog_manage_ft',
	columns:[[
		{field:'id',hidden:'true'},
		{field:'user_id',hidden:'true'},
		{field:'dept_name',title:'部门',width:80,align:'center'},
		{field:'role_name',title:'职务',width:80,align:'center'},
		{field:'user_name',title:'姓名',width:80,align:'center'},
		{field:'log_date',title:'日期',width:100,align:'center'},
		{field:'log_w',title:'星期',width:80,align:'center'},
		{field:'log_am',title:'上午',width:200},
		{field:'log_pm',title:'下午',width:200},
		{field:'log_morn',title:'明天预安排',width:200}
	]],
	onDblClickRow:function(index,data){
		var str = data.log_date.replace(/-/g,'/'); 
		var date = new Date(str); 
		//var time = date.getTime();
		$.cachedScript('<?php echo base_url('data/other/js/worklog.js')?>').done(function () { new_worklog(date)}); 
	},
	onLoadSuccess:function(data){ 
		var pager = $(this).datagrid('getPager');
			pager.pagination({
				displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
			});
	}
});	

function selectuser_tree_stint(){
	$('#selectuser_tree_stint').tree({
		onSelect : function(node) {
			//返回树对象
			var tree = $(this).tree;
			//选中的节点是否为叶子节点,如果不是叶子节点,清除选中
			var isLeaf = tree('isLeaf', node.target);
			if (!isLeaf) {
				//清除选中
				$('#selectuser_tree_stint').tree('toggle',node.target);
				//$.messager.alert('警告','请选择子部门!','warning');
			}else{			
				$('#selectuser_tree_stint').tree({
					onClick: function(node){
						//alert(node.text);  // alert node text property when clicked
						$('#selectuser_list_stint').datagrid({
							url:'<?php echo base_url('systemmanage/user_data');?>/'+node.id,
							title:node.text+' 用户列表',
							showHeader:false,
							loadMsg:'加载中',
							nowrap:false,
							fit:true,
							fitColumns:true,
							border:false,
							columns:[[
								{field:'user_name',width:180,align: 'center'}
							]],
							onClickRow:function(index,data){
								if(data.id){   /*如果返回列表，则执行插入用户和选中动作，否则不许插入并取消选中*/
									click_user(data);	
								}else{
									$('#selectuser_list_stint').datagrid("unselectRow", index);//
								}
							},
							onLoadSuccess:function(data){//当数据加载成功时触发 
								if(data.total){/*如果查询的用户列表不为0行，则执行插入和选中动作，否则在用户列表位置插入‘暂无用户’提示*/
									begin_set();
								}else{
									$('#selectuser_list_stint').datagrid('appendRow',{
										user_name: '暂无用户'
									});
								}
							}
						});
					}
				});
			}
		},
		onCheck:function(node, checked){ 
			if(checked){
				$.get("<?php echo base_url('selectuser/getcheckeduser');?>/"+node.id,function(result){
					add_all(result);
				},'json');
			}else{
				$.get("<?php echo base_url('selectuser/getcheckeduser');?>/"+node.id,function(result){
					del_all(result);	
				},'json');
			}
		} 		
	});
}
selectuser_tree_stint();

function worklog_manage_search_submit(m){
	var queryParams = $('#'+m+'_list').datagrid('options').queryParams;  
		if($("#"+m+"_search_select_id").val())
			queryParams.user_id = $("#"+m+"_search_select_id").val();
		else
			delete queryParams.user_id;
		if($("#role_id_log").combobox('getValue'))
			queryParams.role_id_log = $("#role_id_log").combobox('getValue');
		else
			delete queryParams.role_id_log;
		if($("#"+m+"_ids").datebox('getValue'))
			queryParams.wids = $("#"+m+"_ids").datebox('getValue');
		else
			delete queryParams.wids;
			
		if($("#"+m+"_ide").datebox('getValue'))
			queryParams.wide = $("#"+m+"_ide").datebox('getValue');
		else
			delete queryParams.wide;

	$('#'+m+'_list').datagrid('options').queryParams=queryParams;        
	$('#'+m+'_list').datagrid('reload'); 

}

function count(o){
	var t = typeof o;
	if(t == 'string'){
		return o.length;
	}else if(t == 'object'){
		var n = 0;
		for(var i in o){
			n++;
		}
		return n;
	}
	return false; 
}
function worklog_table(m){
	var str = {};
	if($("#"+m+"_search_select_id").val()){
		//str.user_name = $("#"+m+"_search_select_user").val();
		str.user_id = $("#"+m+"_search_select_id").val();
	}else
		delete str.user_id;

	if($("#role_id_log").combobox('getValue'))
		str.role_id_log = $("#role_id_log").combobox('getValue');
	else
		delete str.role_id_log;

	if($("#"+m+"_ids").datebox('getValue'))
		str.wids = $("#"+m+"_ids").datebox('getValue');
	else
		delete str.wids;
		
	if($("#"+m+"_ide").datebox('getValue'))
		str.wide = $("#"+m+"_ide").datebox('getValue');
	else
		delete str.wide;
	
	if(count(str)>0){
		$.post("<?php echo base_url('worklog/worklog_table');?>",str,
		function(data,status){
			//alert("Data: " + data.success + "\nStatus: " + status);
			window.location.href = '<?php echo base_url('worklog/worklog_down');?>';
		},'JSON');
	}else{
		$.messager.alert('提示','要导出结果，请先设置查询参数!','warning');
	}

}

//清空该页上的选择用户表单
function clearuser_stint(){
	$("#"+destination_id+"_select_id").val('');
	$("#"+destination_id+"_select_user").val('');
	selectuser_tree_stint();
	$('#selectuser_list_stint').datagrid('loadData', { total: 0, rows: [] });
}
</script>